package top.revery.task.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RestController;
import top.revery.api.api.task.ILogTaskApi;
import top.revery.api.config.UserPageData;
import top.revery.api.entity.task.BaseLogTask;

import top.revery.task.dto.LogTaskDto;
import top.revery.task.service.LogTaskService;

import java.util.Map;

/**
 * @author denghao
 * @title  作品
 * @date 2019/12/14 14:01
 */
@RestController
@Slf4j
public class LogTaskController implements ILogTaskApi {
    @Autowired
    private LogTaskDto logTaskDto;
    @Autowired
    private LogTaskService logTaskService;

    //保存
    @Override
    public BaseLogTask save(BaseLogTask baseLogTask) throws Exception {

        try {
            return logTaskDto.save(baseLogTask);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    //多条件分页查询
    @Override
    public UserPageData getList(int pageNum, int pageSize, Map map) {
        try {
            Page<BaseLogTask> pageList = logTaskService.findPage(pageNum, pageSize, map);
            UserPageData userPageData = new UserPageData();
            userPageData.list = pageList.getContent();
            userPageData.rows = pageList.getTotalElements();
            return userPageData;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
